package com.changli02.stringmore;

import org.junit.Test;

public class StringBufferMethodTest {
    @Test
    public void test1() {
        StringBuffer sb = new StringBuffer();
        sb.append("abc").append("def").append("123");
        System.out.println(sb);
    }
    @Test
    public void test2() {
        StringBuffer sb = new StringBuffer();
        sb.append("abc").append("def").append("123");
        //左闭右开
        sb.delete(3,5+1);
        System.out.println(sb);  //abc123
        sb.deleteCharAt(1); // ac123
        System.out.println(sb);

    }
    @Test
    public void test3() {
        StringBuffer sb = new StringBuffer();
        sb.append("abc").append("def").append("123");
        sb.replace(0,3,"i love you zky");
        System.out.println(sb);

        sb.setCharAt(17,'5');
        sb.setCharAt(18,'2');
        sb.setCharAt(19,'0');
        System.out.println(sb);
    }
    @Test
    public void test4() {
        StringBuffer sb = new StringBuffer();
        sb.append("abc").append("def").append("123");
        sb.insert(3,"i love you zky");
        System.out.println(sb);
    }
    @Test
    public void test5() {
        StringBuffer sb = new StringBuffer();
        sb.append("abc").append("def").append("123");
        System.out.println(sb.charAt(4));
    }
}
